Skip to content

fix: text classifier crash in Android - #112

Merged
IvanIhnatsiuk merged 2 commits into
developmentfrom
fix/text-classifier-class-on-android
Jun 27, 2026
Merged

fix: text classifier crash in Android#112
IvanIhnatsiuk merged 2 commits into
developmentfrom
fix/text-classifier-class-on-android

Conversation

@IvanIhnatsiuk

@IvanIhnatsiuk IvanIhnatsiuk commented Jun 27, 2026

Copy link
Copy Markdown
Collaborator

`

Summary

This pull request introduces a custom EnrichedTextClassifier to enhance text classification behavior in the EnrichedTextInputView component, especially when handling special replacement characters. The changes ensure that text selection and classification are more robust in the presence of these characters, and that the custom classifier is used on supported Android versions.

Custom Text Classification Integration:

  • Added a new EnrichedTextClassifier class that wraps the default TextClassifier and overrides selection and classification logic to account for replacement blocks (special characters), preventing undesired behavior when these are present. (EnrichedTextClassifier.kt,
  • Integrated EnrichedTextClassifier into EnrichedTextInputView for devices running Android O (API 26) or higher, ensuring the view uses the custom classifier when available. (EnrichedTextInputView.kt,
    Text Classifier State Management:

Test Plan

  1. Open the editor screen
  2. Try to press on the MDF/content blocks

Screenshots / Videos

Before

Screen.Recording.2026-06-27.at.12.25.15.mov

After

Screen.Recording.2026-06-27.at.12.22.03.mov

Include any visual proof that helps reviewers understand the change — UI updates, bug reproduction or the result of the fix.

Compatibility

OS Implemented
iOS
Android
Web

Checklist

  • E2E tests are passing
  • Required E2E tests have been added (if applicable)

@IvanIhnatsiuk
IvanIhnatsiuk requested a review from Copilot June 27, 2026 10:25
@IvanIhnatsiuk IvanIhnatsiuk self-assigned this Jun 27, 2026
@IvanIhnatsiuk
IvanIhnatsiuk merged commit 8d1653b into development Jun 27, 2026
1 check passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to improve Android text selection/classification behavior in EnrichedTextInputView when the text contains object-replacement characters (e.g., embedded content blocks) by installing a custom TextClassifier wrapper.

Changes:

  • Added EnrichedTextClassifier to suppress selection/classification when the selection touches object-replacement characters.
  • Integrated the custom classifier into EnrichedTextInputView for newer Android versions.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
android/src/main/java/com/swmansion/enriched/EnrichedTextInputView.kt Installs a custom text classifier in the EditText initialization flow (but currently with API-level compatibility hazards).
android/src/main/java/com/swmansion/enriched/EnrichedTextClassifier.kt Adds a TextClassifier wrapper to bypass selection/classification near replacement characters (but currently annotated too loosely for the APIs it references).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

private var typefaceDirty = false

private var inputMethodManager: InputMethodManager? = null
private var enrichedTextClassifier: EnrichedTextClassifier? = null
Comment on lines +214 to 220
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
enrichedTextClassifier =
EnrichedTextClassifier(textClassifier).also {
setTextClassifier(it)
}
}
}
transformationMethod = LineSeparatorTransformationMethod()
addTextChangedListener(EnrichedTextWatcher(this))
filters = arrayOf(NonEditableParagraphFilter(), ParagraphLimitFilter(this))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Comment on lines +10 to +28
@RequiresApi(Build.VERSION_CODES.O)
internal class EnrichedTextClassifier(
private val delegate: TextClassifier,
) : TextClassifier {
@RequiresApi(Build.VERSION_CODES.P)
override fun suggestSelection(request: TextSelection.Request): TextSelection =
if (touchesReplacementBlock(request.text, request.startIndex, request.endIndex)) {
TextSelection.Builder(request.startIndex, request.endIndex).build()
} else {
delegate.suggestSelection(request)
}

@RequiresApi(Build.VERSION_CODES.P)
override fun classifyText(request: TextClassification.Request): TextClassification =
if (touchesReplacementBlock(request.text, request.startIndex, request.endIndex)) {
TextClassification.Builder().build()
} else {
delegate.classifyText(request)
}
@IvanIhnatsiuk IvanIhnatsiuk changed the title fix: text classifier class in Android implementation fix: text classifier crash in Android Jun 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants